<template>
  <div class="update-password">
    <!-- 导航栏 -->
    <van-nav-bar title="修改密码"
                 left-arrow
                 @click-left="comeBackHome" />
    <div class="main-cont">
      <p class="tips">修改密码</p>
      <!-- 添加表单 -->
      <van-form @submit="onSubmit"
                @failed="onFailed">
        <van-field v-model="form.oldpassword"
                   name="oldpass"
                   label="原密码"
                   placeholder="请输入原密码"
                   :rules="[{ required: true}]" />
        <van-field v-model="form.newpassword"
                   name="newpass"
                   label="新密码"
                   placeholder="请输入新密码"
                   :rules="[{ required: true }]" />

        <div class="btn">
          <van-button round
                      block
                      color="#e87b61"
                      native-type="submit">更改密码</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { userPhone } from '@/utils/token'
import {updtepass} from '@/api/main'
export default {
  data() {
    return {
      form: {
        user_phone: userPhone(),
        oldpassword: '',
        newpassword: ''
      }
    }
  },
  methods: {
    comeBackHome() {
      this.$router.go(-1)
    },
    // 提交修改内容
    async onSubmit() {
      console.log(this.form)
      let res = await updtepass(this.form)
      console.log(res)
      this.$toast(res.message)
      if(res.status==200){
        this.$router.push('/')
      }
    },
    onFailed() {
      this.$toast('请填入内容')
    }
  },
  created() {}
}
</script>

<style lang="less" scoped>
.update-password {
  background-color: #f6f6f6;
  height: 100vh;
  /* 导航栏 */
  ::v-deep .van-nav-bar__content {
    height: 1.6rem;
    background-color: #e87b61;
    /* 左侧图标 */
    .van-nav-bar__left {
      .van-icon {
        color: #fff;
        font-size: 0.64rem;
      }
    }
    /* 标题 ，文字颜色*/
    .van-nav-bar__title {
      font-size: 0.56rem;
      color: #fff;
      letter-spacing: 0.0267rem;
    }
  }
  /* 主要内容 */
  .main-cont {
    padding: 0 0.1867rem;
    .tips {
      margin: 0.16rem 0 0.4rem 0;
      padding: 0.1867rem 0.2667rem;
      font-size: 0.3733rem;
      background-color: #fff;
      color: #666;
    }
    ::v-deep .van-cell {
      margin-top: 10px;
      padding: 13px 16px;
      border-radius: 0.1067rem;
      .van-field__label {
        margin-right: 0.4rem;
        width: auto;
        font-size: 0.4267rem;
        font-weight: 600;
      }
    }
    ::v-deep .btn {
      margin: 270px auto 0;
      width: 90%;
      .van-button--normal {
        font-size: 0.48rem;
        letter-spacing: 1px;
      }
    }
  }
}
</style>